package com.ruoyi.project.module.utils;

import com.ruoyi.project.module.domain.domain.Domain;
import com.ruoyi.project.module.project.domain.Project;
import com.ruoyi.project.module.project.service.IProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * com.ruoyi.project.module.utils.ProjectUtils <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  2018-10-09 12:02:18<br>
 * ブログ http://shoukaiseki.blog.163.com/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/

public class ProjectUtils {
    static final Logger logger= LoggerFactory.getLogger(ProjectUtils.class);

    public static Domain getDomainByProject(IProjectService projectService, Project project){
        Project projectTemp=project;
        while (projectTemp!=null){
            logger.debug("projectid={},domainid={}",projectTemp.getApiProjectnameId(),projectTemp.getApiDomainId());
            if(projectTemp.getApiDomainId()!=null){
                return projectTemp.getDomain();
            }
            projectTemp = projectService.selectProjectById(projectTemp.getParentId());
        }

        return null;

    }

    public static  Integer getErrorGroupByProject(IProjectService projectService, Project project){
        Project projectTemp=project;
        while (projectTemp!=null){
            logger.debug("projectid={},errorGroup={}",projectTemp.getApiProjectnameId(),projectTemp.getErrorGroup());
            if(projectTemp.getErrorGroup()!=null){
                return projectTemp.getErrorGroup();
            }
            projectTemp = projectService.selectProjectById(projectTemp.getParentId());
        }

        return null;

    }


}
